package com.ly.Threaduse;

public class Thread02 {
    public static void main(String[] args) {
//        Dog dog = new Dog();
//        //dog.start(); 不能调用
//        //创建一个Thread对象，把dog对象(实现Runnable)
//        Thread thread = new Thread(dog);
//        thread.start();
        Tiger tiger = new Tiger();
        ThreadProxy threadProxy = new ThreadProxy(tiger);
        threadProxy.start();
    }
}
class Animal{}
class Tiger extends Animal implements Runnable{

    @Override
    public void run() {
        System.out.println("老虎叫...");
    }
}


class Dog implements Runnable{

    int count=0;
    @Override
    public void run() { //普通方法
        while (true){
            System.out.println("小狗叫.."+count+Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            count++;
            if (count==10){
                break;
            }

        }
    }
}

//线程代理类
class ThreadProxy implements Runnable{
    private Runnable target = null;//属性 类型是Runnable
    @Override
    public void run() {
        if (target!=null){
            target.run();
        }
    }//你可以把Proxy类当做Thread类
    //构造器
    public ThreadProxy(Runnable target) {
        this.target = target;
    }
    public void start(){
        start0();//这个方法是直正实现多线程方法
    }

    private void start0() {
        run();
    }
}
